package com.example.filter;

import org.springframework.stereotype.Service;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * Project:SingleSignOnFilter
 * Description:  自定义过滤器，并通过@WebFilter注册
 * Created by:王骁 wangxiao5@asiainfo-sec.com
 * Created at:2024/10/16 17:20
 */
@Service
@WebFilter
public class SingleSignOnFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) servletRequest;
        String requestUri = req.getRequestURI();
        if (requestUri.contains("/ssoLogin")) {
            // 如果满足特定条件，执行相应的逻辑
            // sessionRegistry.registerNewSession(req.getSession().getId(), SecurityContextHolder.getContext().getAuthentication());
        }
        filterChain.doFilter(servletRequest, servletResponse);
    }

    @Override
    public void destroy() {

    }
}